/*
 * Copyright 2011-2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0.
 * See `LICENSE` in the project root for license information.
 */

package me.ijleex.platform.system.authn.action;

import jakarta.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import me.ijleex.platform.framework.entity.Result;
import me.ijleex.platform.framework.spring.ControllerSupport;
import me.ijleex.platform.framework.util.RandomStringUtils;
import me.ijleex.platform.system.authn.vo.Login;

/**
 * LoginAction.
 *
 * @author liym
 * @since 2021-07-10 18:02 新建
 */
@RestController
public class LoginAction extends ControllerSupport<Result> {

    public LoginAction() {
    }

    @PostMapping(path = "/login")
    public Result login(HttpServletRequest request, @RequestBody Login login) {
        String loginId = login.getLoginId();
        String password = login.getPassword();
        if ("admin".equals(loginId) && "123456".equals(password)) {
            return Result.ok("OK").addData("token", RandomStringUtils.generate(25));
        }
        return Result.error("管理员名或密码错误");
    }

    @PostMapping(path = "/logout")
    public Result logout(HttpServletRequest request) {
        return Result.ok("OK");
    }

}
